<?php
namespace App\Model\Movie;
use PhalApi\Model\DataModel;

class MovieDetail extends DataModel {

    protected function getTableName($id) {
        return 'detail';
    }

    public function getList($id) {
        $res = $this->getORM()->select('*')->where('source_id',$id)->fetchAll();
        foreach ($res as $key=>$value){
            $res[$key]=array_merge($value,array('show'=>false));
        }
        return $res;
    }

    public function getMovieDetailInfo($id) {
        $res = $this->getORM()->select('video_url','video_type')->where('source_id',$id)->where('video_type != ?','xunlei')->fetchAll();
        $video_type = [];
        foreach ($res as $k=>$v){
            $video_type[]=$v['video_type'];
            $video_serie=json_decode($v['video_url'],true);
        }
        $video_series = [];
        foreach($video_serie[1] as $key=>$value){
            $video_series[$key]['txt']=array_keys($value)[0];
            $video_series[$key]['url']=strpos(array_values($value)[0],'m3u8')?'https://www.kuyunjiexi.com/?url='.array_values($value)[0]:array_values($value)[0];
        }
        return ['video_type'=>array_merge(array_unique($video_type)),'video_series'=>$video_series];
    }
}